package com.leyou.auth.web;

import com.leyou.auth.service.UserAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @description:
 * @author: YHL
 * @time: 2021/3/5 11:21
 */
@RestController
@RequestMapping("/user")
public class UserAuthController {
    @Autowired
    private UserAuthService userAuthService;
    /**
     * 用户登录
     * @param username
     * @param password
     * @return
     */
    @PostMapping("/login")
    public ResponseEntity<Void>userLogin(
            @RequestParam("username")String username,
            @RequestParam("password")String password,
            HttpServletResponse response){
       this.userAuthService.userLogin(username,password,response);
       return ResponseEntity.ok().build();
    }

    /**
     * 退出登录
     * @param request
     * @param response
     * @return
     */

@PostMapping("/logout")
    public ResponseEntity<Void>userLogOut(
            HttpServletRequest request,
            HttpServletResponse response) {
    this.userAuthService.userLogOut(request, response);
    return ResponseEntity.ok().build();
}
}
